const Sequelize = require('sequelize');

/**
 * 权限表
 */
exports.Permissions = {
  name: {type: Sequelize.STRING(30), allowNull: true},
  object_type: {
    type: Sequelize.STRING(30), allowNull: false,
    unique: 'permission_object_action'
  },
  action_type: {
    type: Sequelize.STRING(30), allowNull: false,
    unique: 'permission_object_action'
  }
}

/**
 * 角色权限表
 */
exports.PermissionsRoles = {
  role: {
    type: Sequelize.STRING(30), allowNull: true,
    unique: 'permission_role'
  },
  permission_id: {
    type: Sequelize.INTEGER, references: {model: 'Permissions', key: 'id'}, allowNull: true,
    unique: 'permission_role'
  }
}

/**
 * 用户表
 */
exports.Users = {
  unionid: {type: Sequelize.STRING(50), allowNull: true},
  openid: {type: Sequelize.STRING(50), allowNull: true, unique: 'openid'},
  tel: {type: Sequelize.STRING(30), allowNull: true, unique: 'tel', permissions: ['User', 'Admin']},
  nickname: {type: Sequelize.STRING(50), allowNull: true, permissions: ['User', 'Admin']},
  username: {type: Sequelize.STRING(50), allowNull: true, unique: 'username', permissions: ['User', 'Admin']},
  image: {type: Sequelize.STRING(191), allowNull: true, permissions: ['User', 'Admin']},
  banner: {type: Sequelize.STRING(191), allowNull: true, permissions: ['User', 'Admin']},

  join_qrcode: {type: Sequelize.STRING(191), allowNull: true, permissions: ['User', 'Admin']},
  join_qrcode_mediaid: {type: Sequelize.STRING(191), allowNull: true, permissions: ['Admin'], comments: '加入二维码'},

  return_qrcode: {type: Sequelize.STRING(191), allowNull: true, permissions: ['User', 'Admin']},
  return_qrcode_mediaid: {type: Sequelize.STRING(191), allowNull: true, permissions: ['Admin'], comments: '二维码媒体编号'},

  email: {type: Sequelize.STRING(30), allowNull: true, permissions: ['User', 'Admin']},
  qq: {type: Sequelize.STRING(30), allowNull: true, permissions: ['User', 'Admin']},

  bank_type: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户类型', permissions: ['User']},
  bank_name: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户名称', permissions: ['User']},
  bank_no: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户账号', permissions: ['User']},
  bank_tel: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户对应手机号', permissions: ['User']},

  level: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Normal', comments: '会员级别',
    permissions: ['Admin']
  },
  until: {type: Sequelize.DATE, allowNull: true, comments: '会员到期时间', permissions: ['Admin']},
  agency_at: {type: Sequelize.DATE, allowNull: true, comments: '成为代理时间', permissions: ['Admin']},

  pulse: {type: Sequelize.DATE, allowNull: true, comments: '最近活动时间'},
  last_order: {type: Sequelize.DATE, allowNull: true, comments: '最后用户下单时间'},
  role: {type: Sequelize.STRING(30), allowNull: false, defaultValue: 'User', comments: '角色', permissions: ['Admin']},

  domain: {type: Sequelize.STRING(30), allowNull: true, comments: '域名', permissions: ['Admin']},
  domain_pid: {type: Sequelize.STRING(160), allowNull: true, comments: '域名pid', permissions: ['Admin']},
  domain_alimamaId: {type: Sequelize.STRING(30), allowNull: true, comments: '用户编号ID'},
  domain_mediumId: {type: Sequelize.STRING(30), allowNull: true, comments: '来源媒体ID'},
  domain_adPositionId: {type: Sequelize.STRING(30), allowNull: true, comments: '广告位ID'},

  qun_pid: {type: Sequelize.STRING(160), allowNull: true, comments: '群pid', permissions: ['Admin']},
  qun_alimamaId: {type: Sequelize.STRING(30), allowNull: true, comments: '用户编号ID'},
  qun_mediumId: {type: Sequelize.STRING(30), allowNull: true, comments: '来源媒体ID'},
  qun_adPositionId: {type: Sequelize.STRING(30), allowNull: true, comments: '广告位ID'},

  view_level: {
    type: Sequelize.INTEGER(1),
    allowNull: false,
    defaultValue: 0,
    permissions: ['Admin'],
    comments: '查看数据级别'
  },

  partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级合伙人编号', permissions: ['Admin']},
  agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级代理编号', permissions: ['Admin']},
  inviter_id: {type: Sequelize.INTEGER, allowNull: true, comments: '邀请者编号', permissions: ['Admin']},

  invite_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '我的粉丝数量'},
  agency_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '下级代理数量'},
  member_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '下级会员数量'},

  order_return_scale: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '订单返现比例',
    permissions: ['User', 'Admin']
  },
  order_return_limit: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '订单最低返现金额',
    permissions: ['User', 'Admin']
  },
  first_return_scale: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '首次返现比例',
    permissions: ['User', 'Admin']
  },
  first_return_limit: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '首次最低返现金额',
    permissions: ['User', 'Admin']
  },

  return_quick: {
    type: Sequelize.INTEGER(1),
    allowNull: true,
    defaultValue: 0,
    permissions: ['Admin'],
    comments: '下单立返'
  },
  first_quick: {
    type: Sequelize.INTEGER(1),
    allowNull: true,
    defaultValue: 0,
    permissions: ['Admin'],
    comments: '首次立返'
  },

  agency_scale: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '代理分成比例',
    permissions: ['Admin']
  },
  inviter_agency_scale: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '上级代理分成比例',
    permissions: ['Admin']
  },
  inviter_scale: {
    type: Sequelize.DECIMAL(10, 2),
    allowNull: false,
    defaultValue: 0.00,
    comments: '邀请人返现比例',
    permissions: ['Admin']
  },

  order_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '订单数量'},
  finish_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '订单成功数量'},
  sham_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '虚假数量'},

  amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '账户总额'},
  frozen: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '冻结金额'},
  point: {type: Sequelize.INTEGER(8), allowNull: false, defaultValue: 0, comments: '积分'},
  last_withdraw: {type: Sequelize.DATE, allowNull: true, comments: '最后提现时间, 用户佣金提现'},

  agency_total_income: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '代理总收入'},
  agency_last_settle: {type: Sequelize.DATE, allowNull: true, comments: '最后结算时间, 代理佣金结算'},
  agency_auto_settle: {
    type: Sequelize.INTEGER(1),
    allowNull: false,
    defaultValue: 0,
    permissions: ['Admin'],
    comments: '代理是否自动结算'
  },

  session: {
    type: Sequelize.STRING(160),
    allowNull: true,
    comments: 'session https://oauth.taobao.com/authorize?response_type=token&client_id=23196777&state=1212&view=web',
    permissions: ['User', 'Admin']
  },
  refresh_token: {type: Sequelize.STRING(160), allowNull: true, comments: 'refresh_token', permissions: ['User', 'Admin']},
  session_at: {type: Sequelize.DATE, allowNull: true, comments: 'session授权时间', permissions: ['User', 'Admin']},

  tao_user: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝用户名', permissions: ['Admin']},
  pid: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝联盟pid', permissions: ['Admin']},
  alimamaId: {type: Sequelize.STRING(30), allowNull: true, comments: '用户编号ID'},
  mediumId: {type: Sequelize.STRING(30), allowNull: true, comments: '来源媒体ID'},
  adPositionId: {type: Sequelize.STRING(30), allowNull: true, comments: '广告位ID'},

  jd_user: {type: Sequelize.STRING(160), allowNull: true, comments: '京东用户名', permissions: ['Admin']},
  jd_pid: {type: Sequelize.STRING(160), allowNull: true, comments: '京东pid', permissions: ['Admin']},

  we_id: {type: Sequelize.STRING(160), allowNull: true, comments: '微信分享模板编号', permissions: ['User', 'Admin']},
  qq_id: {type: Sequelize.STRING(160), allowNull: true, comments: 'QQ分享模板编号', permissions: ['User', 'Admin']},

  notifyAllOrder: {
    type: Sequelize.INTEGER,
    allowNull: false,
    defaultValue: 1,
    comments: '订单通知',
    permissions: ['User', 'Admin']
  },
  notifyMyOrder: {
    type: Sequelize.INTEGER,
    allowNull: false,
    defaultValue: 1,
    comments: '订单通知',
    permissions: ['User', 'Admin']
  },

  subscribe: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '是否关注'},
  sex: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '性别'},

  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据', permissions: ['User', 'Admin']},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Active', 'Deactivated']]},
    permissions: ['Admin']
  }
}

/**
 * 访问日志表
 */
exports.VisitsLogs = {
  user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},
  ip: {type: Sequelize.STRING(100), allowNull: true, comments: 'ip地址'}
}

/**
 * 登录日志表
 */
exports.LoginLogs = {
  sid: {type: Sequelize.STRING(100), allowNull: true, comments: 'session id'},
  is_void: {type: Sequelize.INTEGER(1), allowNull: true, defaultValue: 0, comments: '是否无效, 默认有效'},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  user_id: {type: Sequelize.INTEGER, allowNull: false, comments: '操作人员'}
}

/**
 * 认证表
 */
exports.Auths = {
  password: {type: Sequelize.STRING(160), allowNull: false},
  type: {
    type: Sequelize.STRING(30),
    allowNull: false,
    defaultValue: 'Login',
    validate: {isIn: [['Login', 'Payment']]},
    unique: 'type_user_id'
  },
  user_id: {
    type: Sequelize.INTEGER,
    references: {model: 'Users', key: 'id'},
    allowNull: false,
    unique: 'type_user_id'
  }
}

/**
 * 用户资金流水表
 */
exports.UsersFinances = {
  partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级合伙人编号', permissions: ['Admin']},
  user_id: {
    type: Sequelize.INTEGER,
    references: {model: 'Users', key: 'id'},
    allowNull: false
  },
  amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '入账金额'},
  charge: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '手续费'},
  rate_scale: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '手续费比例'},
  type: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'In',
    validate: {isIn: [['In', 'Out', 'Pay']]}
  },
  operation: {
    type: Sequelize.STRING(30),
    allowNull: false,
    comments: 'Return, Withdraw ...'
  },
  by: {
    type: Sequelize.STRING(30), allowNull: false, comments: '支付宝, 微信...'
  },
  order_id: {type: Sequelize.STRING(60), allowNull: true},
  payment_no: {type: Sequelize.STRING(60), allowNull: true, unique: 'payment_no, 第三方系统产生的支付号'},
  note: {type: Sequelize.STRING(160), allowNull: true, comments: '交易备注'},
  fail_times: {type: Sequelize.INTEGER(3), allowNull: false, defaultValue: 0, comments: '结算失败次数'},
  is_settled: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否已经结算'},
  is_amount: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否入账, 把数据算入Amount表'},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
    validate: {isIn: [['Pending', 'Successful', 'Failed']]}
  }
}

/**
 * 用户结算、提现表
 */
exports.UsersWithdraws = {
  partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级合伙人编号', permissions: ['Admin']},
  user_id: {
    type: Sequelize.INTEGER,
    references: {model: 'Users', key: 'id'},
    allowNull: false
  },
  trade_no: {type: Sequelize.STRING(50), allowNull: true, unique: 'trade_no'},
  total_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00},
  charge: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '手续费'},
  rate_scale: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '平台费用比例'},
  amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '实际到账'},
  bank_type: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户类型'},
  bank_name: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户名称'},
  bank_no: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户账号'},
  bank_tel: {type: Sequelize.STRING(30), allowNull: true, comments: '银行账户对应手机号'},
  note: {type: Sequelize.STRING(160), allowNull: true},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
    validate: {isIn: [['Pending', 'Successful', 'Failed']]}
  }
}

/**
 * 提现操作日志表
 */
exports.WithdrawsLogs = {
  opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
  reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'}
}

/**
 * 代理结算表
 */
exports.AgencysSettles = {
  type: {type: Sequelize.STRING(30), allowNull: true, comments: '结算平台'},
  partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '合伙人编号'},
  agency_id: {type: Sequelize.STRING(30), allowNull: true, comments: '代理编号'},
  inviter_agency_id: {type: Sequelize.STRING(30), allowNull: true, comments: '上级代理编号'},

  total_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '结算总佣金'},
  back_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '退回总佣金'},

  settle_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '结算金额'},

  agency_scale: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '结算比例'},
  agency_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '代理实际到账'},

  inviter_agency_scale: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '上级结算比例'},
  inviter_agency_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '上级代理实际到账'},

  note: {type: Sequelize.STRING(160), allowNull: true},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},

  auto_amount: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '自动入账'},
  is_amount: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否入账，返现进入账号冻结(用户和邀请人)'},
  is_payed: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '佣金是否支付(手动)'},
  is_back: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '佣金是否返回'}
}

/**
 * 结算操作日志表
 */
exports.SettlesLogs = {
  opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
  reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'}
}

/**
 * 设置表
 */
exports.Settings = {
  name: {type: Sequelize.STRING(50), allowNull: false, unique: 'name'},
  type: {type: Sequelize.STRING(30), allowNull: false, defaultValue: 'String'},
  value: {type: Sequelize.TEXT, allowNull: true}
}

/**
 * 字典表
 */
exports.Dicts = {
  type: {type: Sequelize.STRING(30), allowNull: false, unique: 'dict_type_value'},
  value: {type: Sequelize.STRING(50), allowNull: false, unique: 'dict_type_value'},
  text: {type: Sequelize.STRING(191), allowNull: false},
  icon: {type: Sequelize.STRING(160), allowNull: true},
  color: {type: Sequelize.STRING(30), allowNull: true},
  feature: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否推荐'},
  order_by: {type: Sequelize.INTEGER(9), allowNull: true, defaultValue: 0},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Active', 'Deactivated']]}
  }
}

/**
 * 帮助与反馈
 */
exports.Suggestions = {
  type: {type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Other'},
  content: {type: Sequelize.TEXT, allowNull: true},
  images: {type: Sequelize.TEXT, allowNull: true, comments: '图片列表'},
  tel: {type: Sequelize.STRING(30), allowNull: true},
  qq: {type: Sequelize.STRING(30), allowNull: true},
  email: {type: Sequelize.STRING(30), allowNull: true},
  user_id: {type: Sequelize.INTEGER, allowNull: true},
  feature: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0},
  order_by: {type: Sequelize.INTEGER(9), allowNull: true, defaultValue: 0},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Active', 'Deactivated']]}
  }
}

/**
 * 文章/详情表
 */
exports.Articles = {
  type: {type: Sequelize.STRING(30), allowNull: false},
  slug: {type: Sequelize.STRING(100), allowNull: true},
  title: {type: Sequelize.STRING(160), allowNull: true},
  keywords: {type: Sequelize.STRING(160), allowNull: true},
  description: {type: Sequelize.STRING(191), allowNull: true},
  markdown: {type: Sequelize.TEXT, allowNull: true},
  content: {type: Sequelize.TEXT, allowNull: true},
  image: {type: Sequelize.STRING(160), allowNull: true},
  banner: {type: Sequelize.STRING(160), allowNull: true},
  feature: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0},
  view_count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '浏览次数'},
  collect_count: {type: Sequelize.INTEGER(6), allowNull: false, defaultValue: 0, comments: '收藏者数量'},
  comment_data: {type: Sequelize.TEXT, allowNull: true, comments: '评论数据'},
  order_by: {type: Sequelize.INTEGER(9), allowNull: true, defaultValue: 0},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Active', 'Deactivated']]}
  }
}

/**
 * 图片表
 */
exports.Images = {
  type: {type: Sequelize.STRING(30), allowNull: false},
  reference: {type: Sequelize.INTEGER, allowNull: true},
  tags: {type: Sequelize.STRING(30), allowNull: true},
  bucket: {type: Sequelize.STRING(30), allowNull: true},
  key: {type: Sequelize.STRING(100), allowNull: true},
  image: {type: Sequelize.STRING(160), allowNull: true},
  order_by: {type: Sequelize.INTEGER(9), allowNull: true, defaultValue: 0}
}

/**
 * 日志表
 */
exports.Logs = {
  type: {type: Sequelize.STRING(30), allowNull: false, comments: '类型,如:Login'},
  opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
  role: {type: Sequelize.STRING(30), allowNull: true, comments: '角色'},
  reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
  level: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'}
}

/**
 * 提醒表
 */
exports.Notifications = {
  type: {type: Sequelize.STRING(30), allowNull: false},
  message: {type: Sequelize.STRING(160), allowNull: false},
  read: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  user_id: {type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: true}
}

/**
 * 帮助与反馈
 */
exports.Suggestions = {
  type: {type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Other'},
  content: {type: Sequelize.TEXT, allowNull: true},
  images: {type: Sequelize.TEXT, allowNull: true, comments: '图片列表'},
  tel: {type: Sequelize.STRING(30), allowNull: true},
  qq: {type: Sequelize.STRING(30), allowNull: true},
  email: {type: Sequelize.STRING(30), allowNull: true},
  user_id: {type: Sequelize.INTEGER, allowNull: true},
  feature: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0},
  order_by: {type: Sequelize.INTEGER(9), allowNull: true, defaultValue: 0},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Active', 'Deactivated']]}
  }
}

/**
 * 自动回复
 */
exports.AutoResponses = {
  level: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Normal', unique: 'level_keyword', comments: '会员级别'
  },
  keyword: {type: Sequelize.STRING(160), allowNull: false, unique: 'level_keyword', comments: '关键字'},
  response: {type: Sequelize.TEXT, allowNull: true, comments: '回复内容'},
  order_by: {type: Sequelize.INTEGER(9), allowNull: true, defaultValue: 0},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Active', 'Deactivated']]}
  }
}

/**
 * 红包表
 */
exports.RedPackets = {
  type: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Normal', comments: '红包类型(邀请、直播间)'
  },
  partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级合伙人编号'},
  amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '总额金额'},
  max: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '红包最大金额'},
  min: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '红包最小金额'},
  count: {type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comments: '红包数量'},
  note: {type: Sequelize.STRING(160), allowNull: true, comments: '备注'},
  ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
  feature: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Pending', 'Active', 'Deactivated']]}
  }
}

/**
 * 红包用户表
 */
exports.RedPacketsUsers = {
  type: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Normal', comments: '红包类型(邀请、直播间)'
  },
  redpacket_id: {type: Sequelize.INTEGER, references: {model: 'RedPackets', key: 'id'}, allowNull: false},
  reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
  amount: {type: Sequelize.DECIMAL(10, 2), allowNull: false, defaultValue: 0.00, comments: '总额金额'},

  partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级合伙人编号'},
  agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级代理编号'},
  inviter_id: {type: Sequelize.INTEGER, allowNull: true, comments: '邀请者编号'},
  user_id: {type: Sequelize.INTEGER, allowNull: true},

  is_sham: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否虚假'},
  is_settle: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否结算，返现进入账号余额'},
  is_payed: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '返款是否支付'},
  is_back: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '订单无效, 是否返回'},

  note: {type: Sequelize.STRING(160), allowNull: true, comments: '备注'},
  status: {
    type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Active',
    validate: {isIn: [['Pending', 'Active', 'Deactivated']]}
  }
}

/**
 * 短网址服务
 */
exports.ShortUrls = {
  hash: {type: Sequelize.STRING(50), allowNull: true},
  url: {type: Sequelize.STRING(255), allowNull: true, unique: 'short_url'}
}